package com.example.tests;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import org.testng.annotations.Test;
import com.example.utils.ListOf;
import com.example.fw.Folder;

public class TestFolderCreation extends TestBase {

	@Test
	public void testFolderCreation(){
		Folder newfolder = new Folder()
		.withName("newfolder");
		ListOf<Folder> oldList = app.getFolderHelper().getFolders();
		app.getFolderHelper().createFolder(newfolder);
		ListOf<Folder> newList = app.getFolderHelper().getFolders();
	    assertThat(newList, equalTo(oldList.withAppended(newfolder)));
	}
	
	@Test
	public void testVariousFoldersCreation(){
		Folder newfolder1 = new Folder()
		.withName("newfolder1");
		Folder newfolder2 = new Folder()
		.withName("newfolder2");
		ListOf<Folder> oldList = app.getFolderHelper().getFolders();
		assertThat(app.getFolderHelper().createFolder(newfolder1), is(nullValue()));
		ListOf<Folder> newList1 = app.getFolderHelper().getFolders();
	    assertThat(newList1, equalTo(oldList.withAppended(newfolder1)));
	    assertThat(app.getFolderHelper().createFolder(newfolder2), is(nullValue()));
	    ListOf<Folder> newList2 = app.getFolderHelper().getFolders();
	    assertThat(newList2, equalTo(newList1.withAppended(newfolder2)));
	}
	@Test
	public void testFoldersWithSameNameCreation(){
		Folder newfolder1 = new Folder()
		.withName("newfolder3");
		Folder newfolder2 = new Folder()
		.withName("newfolder3");
		ListOf<Folder> oldList = app.getFolderHelper().getFolders();
		assertThat(app.getFolderHelper().createFolder(newfolder1), is(nullValue()));
		ListOf<Folder> newList1 = app.getFolderHelper().getFolders();
	    assertThat(newList1, equalTo(oldList.withAppended(newfolder2)));
		assertThat(app.getFolderHelper().createFolder(newfolder2), containsString("Duplicated folder name"));
		ListOf<Folder> newList2 = app.getFolderHelper().getFolders();
	    assertThat(newList2, equalTo(newList1));
	}
}
